package cn.bjxy.shishaolong.system.user.service;

import cn.bjxy.shishaolong.request_answer.entity.Answer;
import cn.bjxy.shishaolong.request_answer.entity.Request;
import cn.bjxy.shishaolong.request_answer.service.IRequestService;
import cn.bjxy.shishaolong.system.user.entity.SysUserInfo;
import cn.bjxy.shishaolong.system.user.mapper.SysUserInfoMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 时少龙
 * @since 2019-03-09
 */
@Service
public class UserMainServiceImpl extends ServiceImpl<SysUserInfoMapper, SysUserInfo> implements IUserMainService {

    @Autowired
    private SysUserInfoMapper userInfoMapper;

    @Autowired
    private IRequestService iRequestService;

    @Override
    public Map queryUserRelateCountByUserId(Integer userId) {
        return userInfoMapper.queryUserRelateCountByUserId(userId);
    }

    @Override
    public Request collectDetail(Integer reqAwsType, Integer requestId, Integer reqAwsId) {
        Request request = iRequestService.queryRequestAnswerById(requestId);
        if (request != null) {
            if (reqAwsType == 2) {
                List<Answer> tempAwsList = request.getAnswerList().stream().filter(answer -> reqAwsId.equals(answer.getTid())).collect(Collectors.toList());
                request.setAnswerList(tempAwsList).setAnswerCount(tempAwsList.size());
            }
        }
        return request;
    }
}
